$(function() {
	$('.container .content .box .item .input img').click(function() {
		if ($(this).hasClass('scanPwd')) {
			$(this).removeClass("scanPwd").attr("src", "assets/images/login/hide.png").prev("input")
				.attr("type", "password");
		} else {
			$(this).addClass("scanPwd")
				.attr("src", "assets/images/login/show.png")
				.prev("input")
				.attr("type", "text");
		}
	})
	
	$('.container .content .box .btn button').click(function(){
		if($('#old').val() && $('#password').val() && $('#again').val()){
			if($('#password').val() === $('#again').val()){
				let name = localStorage.getItem('user');
				$.post(
				  `${API_URL}chpwd?username=${name}&oldPwd=${$('#old').val()}&newPwd=${$('#again').val()}`,
				  {},
				  function (res) {
					  console.log(res)
					  let re = eval("(" + res + ")");
					  if(re.code == 200){
						  localStorage.clear()
						  window.location = 'login.html'
					  }else{
						  alert(re.msg)
					  }
				  })
			}else {
				alert('新密码和确认密码不一致')
			}
		}else{
			alert('请将信息输入完全')
		}
	})
	
})
